#@adminLayout() #define main()

<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form_add"  method="post" >
			<div class="form-group">
				<label class="control-label col-sm-2">线路名称:</label>
				<div class="col-sm-3">
					<input type="text" name="linename" class="form-control"  required/>
				</div>
				<label class="control-label col-sm-2">工作日期:</label>
				<div class="col-sm-3">
					<input name="st_date" type="text"  class="form-control"  />
				</div>
			</div>
			
			<div class="form-group">
				<div class="col-sm-10">
					<div id="toolbar">
				        <button type="button" class="btn btn-default"  onclick="addData()">新增</button>
				        <button type="button" class="btn btn-default"  onclick="removeRow()">删除行</button>
				    </div>
            		<table id="jqGrid"></table>
            	</div>
			</div>
		</form>
	</div>

	<div class="row" id="btn">
		<div class="col-sm-offset-3 col-sm-10">
			<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
			<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
			
			
			<button type="button" id="btnExp" class="btn btn-sm btn-primary" onclick="doExp()"><i class="fa fa-download"></i>导出Word </button>
			
		</div>
	</div>
	
	 <script type="text/javascript">
        var prefix = "#(ctx)/ticket_ground_line";
		var id='#(id)';
		var m_id='#(m_id)';
		var temp='#(temp)';
		
		var dotype='#(dotype)';
		
        $(function(){
        	if(dotype=='view')
        	{
        		$('#btn').hide();
        	}
        	
			$('#form_add').loadForm(prefix+'/getData?id='+id);
			bindData(id);
		});
        function submitHandler() {
        	if ($.validate.form()) {
        		var data=$('#form_add').serializeArray();
				data.push({"name": "id", "value": id});
				data.push({"name": "m_id", "value": m_id});
				data.push({"name": "temp", "value": temp});
				data.push({"name": "data", "value": getTableData()});
				
        		$.operate.saveTab(prefix + "/save", data);
			}
	    }
        
		let $table = $('#jqGrid');
    	var lastsel3;
        function bindData(m_id)
        {
        	$table.jqGrid({
                url: prefix + "/list?m_id="+m_id,
                datatype: "json",
                styleUI: 'Bootstrap',//设置jqgrid的全局样式为bootstrap样式 
                colModel: [
                    /* { label: '操作', name: 'opt', width: 80, formatter: function(value, options, row){
                    	return "<a href='#' onclick='removeRow(\'' + row.id + '\')'>删除</a>";
                    }}, */
                    { label: 'id', name: 'id', width: 65,hidden: true,key:true},
                    { label: '序号', name: 'sort', width: 65,editable : true,edittype: 'text'},
                    { label: '编号', name: 'num', width: 100,editable : true,edittype: 'text'},
                    { label: '地址', name: 'address', width: 200,editable : true,edittype: 'text'},
                    { label: '装设人员', name: 'people', width:120,editable : true,edittype: 'text'},
                    { label: '装设完成时间 ', name: 'end_time', width: 200,editable : true,edittype: 'text'},
                    { label: '复合人员 ', name: 'sh', width: 150,editable : true,edittype: 'text'},
                    { label: '拆除人员', name: 'cc', width: 150,editable : true,edittype: 'text'},
                    { label: '拆除时间', name: 'cc_time', width: 200,editable: true,edittype: 'text'},
                    { label: '复核人', name: 'sh2', width: 150,editable : true,edittype: 'text'}
                ],
                width:$(window).width()-60,
                shrinkToFit:false,
                autoScroll: true, 
                height:260,
                cellsubmit: "clientArray",
                multiselect: false,
                editurl :prefix+'/remove',
                onSelectRow : function(id) {
                    if (id && id !== lastsel3) {
                    	//$table.jqGrid('restoreRow', lastsel3); 还原数据
                    	if (lastsel3 != null && lastsel3 != "" && lastsel3.length > 0) {
                    		$table.jqGrid('saveRow', lastsel3);//保存上一行
                        }
                      	$table.jqGrid('editRow', id, true,pickdates);
                      	lastsel3 = id;
                    }
                    else
                    {
                      	lastsel3 = '';
                    }
                  }
            });
        }
        
        //新增行
        function addData()
        {
        	let line_name=$('#line_name').val();
        	let myID = new Date().getTime();
        	//alert(myID);
        	
        	let data = {id:myID,sort:"1", num:"",address:line_name, people:"",end_time:"",sh:"",cc:"",cc_time:"",sh2:""};
        	$table.jqGrid('addRowData',data.id,data);
        }
        //移除行
        function removeRow(){
        	var id=$table.jqGrid("getGridParam","selrow");  
        	$table.jqGrid('saveRow',id);
        	if(id.length>15)
        	{
        		var rowData =$table.jqGrid("getRowData", id);
        		
        		$table.jqGrid('delGridRow', id, {
                    reloadAfterSubmit: false,
                    modal: true,                        //模态窗口  
                    jqModal: true
                });
        	}
        	else
        	{
            	$table.delRowData(id);
        	}
        }
        //获取行数据
        function getTableData(){
        	$table.jqGrid('saveRow', lastsel3);
        	var data=$table.jqGrid('getRowData');
            return JSON.stringify(data);
        }
        

        function reloadData(m_id)
        {
        	$table.jqGrid('clearGridData');  //清空表格
        	$table.jqGrid('setGridParam',{  // 重新加载数据
        		url: prefix + "/list?m_id="+m_id,
                datatype: "json"
        	}).trigger("reloadGrid");
        }
        
        //日期
        function pickdates(id) {
            $("#" + id + "_end_time", "#jqGrid").datetimepicker({
            	timeFormat: "HH:mm",
                dateFormat: "yy-mm-dd"
            });
            $("#" + id + "_cc_time", "#jqGrid").datetimepicker({
            	timeFormat: "HH:mm",
                dateFormat: "yy-mm-dd"
             });
         }
        
        
        function doExp()
        {
        	window.location.href=prefix+"/export?id="+id;
        }
        
    </script>
</body>
#end